/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ewerton
 */
public class Util {

    private DefaultTableModel modelo=new DefaultTableModel();
    Conexao con = new Conexao();

    public DefaultTableModel columnTable(String[] columns){
        int quantColunas = columns.length;
        int cont = 0;
        while(cont < quantColunas){
            modelo.addColumn(columns[cont]);
            cont++;
        }
        return modelo;
    }

    public DefaultTableModel rowTable(String sql, String[] colunasBD){
        try {
            modelo.setNumRows(0);
            con.conecta();
            con.executeSQL(sql);
            con.resultset.first();
            int quantColunas = colunasBD.length;
            Object[] object = new Object[quantColunas];
            do{
                for(int cont = 0; cont < quantColunas; cont ++){
                    object[cont] = con.resultset.getObject(colunasBD[cont]);
                }
                modelo.addRow(object);
            }while(con.resultset.next());
        }catch (Exception ex) {
            //JOptionPane.showMessageDialog(null, ex);
        }
        return modelo;
    }
}
